/**
 * 
 */
package com.massyframework.beanskin.graphql.fetching;

import com.massyframework.beanskin.service.metadata.MetadataRepository;

/**
 * {@link MetadataRepositoryAware}, 元数据仓储感知接口
 * @author huangkh
 *
 */
public interface MetadataRepositoryAware {

	void setMetadataRepository(MetadataRepository metadataRepository);
	
	/**
	 * 尝试向{@code target}绑定{@code metadataRepository}
	 * @param target {@link Object}
	 * @param metadataRepository {@link MetadataRepository}
	 * @return
	 */
	static boolean maybeToBind(Object target, MetadataRepository metadataRepository) {
		if (target == null) return false;
		
		if (target instanceof MetadataRepositoryAware) {
			((MetadataRepositoryAware)target).setMetadataRepository(metadataRepository);
			return true;
		}
		
		return false;
	}
}
